package edu.ycxy.poetry.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.ycxy.poetry.entity.ChaoDai;
import edu.ycxy.poetry.vo.AddDynastyVo;
import edu.ycxy.poetry.vo.UpdateDynastyVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author @xin
 * @createDate 2022/3/8
 * @Description 朝代信息的数据处理层
 */
@Repository
public interface ChaoDaiMapper extends BaseMapper<ChaoDai> {

    //根据朝代名查询详细信息
    @Select("select * from vab_chaodai where name=#{dynastyname}")
    ChaoDai findDynasty(String name);

    //根据朝代的年代顺序进行排序,从远到进
    @Select("select * from vab_chaodai order by id desc")
    List<ChaoDai> findDynastyName();

    //添加朝代
    @Insert("insert into vab_chaodai(name) values (#{name})")
    Integer addDynasty(String name);

    //更新信息
    @Update("update vab_chaodai set name=#{name},txt=#{txt} where id=#{id}")
    Integer updateDynasty(String name,String txt,Integer id);

    //增加朝代详细信息
    @Insert("insert into vab_chaodai(name,txt) values (#{name},#{txt})")
    Integer addNewDynasty(String name,String txt);


    /**
     *
     */
    // 对朝代进行模糊查询
    @Select("select * from vab_chaodai where name like CONCAT ('%',#{title},'%')")
    List<ChaoDai> findListByNameToLike(String title);

    //根据朝代id删除朝代信息
    @Delete("delete from vab_chaodai where id=#{id}")
    Integer deleteDynastyById(Integer id);

    // 根据id查询朝代信息
    @Select("select * from vab_chaodai where id=#{id}")
    UpdateDynastyVo findOneById(Integer id);
}
